#pragma once
#include <common.hpp>
#include "Singleton.hpp"
#include "AnyHolder.hpp"

namespace zzz{
typedef Singleton<AnyHolder> Global;

#define ZGLOBAL_ADD(v, name) zzz::Global::Instance().Add(v, name, false)
#define ZGLOBAL_GET(type, name) (zzz::Global::Instance().Get<type>(name))
#define ZGLOBAL_ISTYPE(type, name) (zzz::Global::Instance().IsType<type>(name))
#define ZGLOBAL_ISEXIST(name) (zzz::Global::Instance().IsExist(name))

template<typename T>
class GlobalRegisterHelper
{
public:
  GlobalRegisterHelper(const string &name, T* var)
  {
    ZGLOBAL_ADD(var, name);
  }
};
#define ZGLOBAL_DEFINE(type, name, default_value) \
  type name = default_value; \
  GlobalRegisterHelper<type> ___GLOBAL_##name##_HELPER___(#name, &name);
}